package com.newworld.dmsapp2.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.newworld.dmsapp2.BaseActivity;
import com.newworld.dmsapp2.R;
import com.newworld.dmsapp2.activity.designtask.AssignAndReassignTaskActivity;
import com.newworld.dmsapp2.bean.Function;
import com.newworld.dmsapp2.bean.InitProgressFunction;
import com.newworld.dmsapp2.bean.InitTaskState;
import com.newworld.dmsapp2.bean.Task;
import com.newworld.dmsapp2.bean.User;
import com.newworld.dmsapp2.fragment.adapter.TodoTaskListAdapter;
import com.newworld.dmsapp2.ui.view.SearchClearEditText;
import com.newworld.dmsapp2.ui.view.XListView;
import com.newworld.dmsapp2.ui.view.XListView.IXListViewListener;
import com.newworld.dmsapp2.util.Config;
import com.newworld.dmsapp2.util.HttpUtil;
import com.newworld.dmsapp2.util.InitFunctionUtil;
import com.newworld.dmsapp2.util.MyPreference;
import com.newworld.dmsapp2.util.SingleSample;
import com.newworld.dmsapp2.util.StringUtil;
import com.newworld.dmsapp2.util.Tool;

public class ToDoTaskListActivity extends BaseActivity implements
		IXListViewListener {
	private XListView mainview;
	private TodoTaskListAdapter taskListAdapter;
	private LinearLayout classify_ll;// 隐藏的项目列表
	private LinearLayout title_list_choose_centerly, title_centeterly;
	private TextView title_list_choose_oneTv, title_list_choose_twoTv;
	private TextView titletext;
	private ListView titleListView;
	private TitleListAdapter titleAdapter;
	private ProgressBar logInBar;
	private SearchClearEditText mClearEditText;// 搜索框
	@SuppressWarnings("unused")
	private TextView searchbtn;// 搜索键
	private boolean refresh = false;
	private String functiontitlename = null;
	private List<Function> functionList = new ArrayList<Function>();
	private ArrayList<String> functionCodeList = new ArrayList<String>();

	
	private boolean canClick = false;
	private int page = 1;
	private String currentPage = null;
	private String Page = "1";
	private String search = "";
	
	private Intent intent;
	private Bundle bundle;
	private User user;
	private String realfunctioncode;
	private String functioncode;
	private String peopleType;
	
	private String areaType = Config.AREACODE_ALL;
	List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

	private List<Task> tasks = new ArrayList<Task>();// new ArrayList<Task>();
	private List<Map<String, Object>> titleList = new ArrayList<Map<String, Object>>();
	private static final String MAP_TITLE = "title";
	// 搜索
	private String editstring = "";
	private List<Task> refreshTasks = new ArrayList<Task>();
	private List<InitProgressFunction> initProgressFunctions = new ArrayList<InitProgressFunction>();
	private String functionPeopleType;
	
	Handler mHandler = new Handler() {
		@SuppressWarnings("unchecked")
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case Config.HANDLE_MSG_RFESH_FAIL:
				Toast.makeText(ToDoTaskListActivity.this, (String) msg.obj,
						Toast.LENGTH_SHORT).show();
				break;
			case Config.HANDLE_MSG_SEARCH_FAIL:
				Toast.makeText(ToDoTaskListActivity.this, (String) msg.obj,
						Toast.LENGTH_SHORT).show();
				break;
			case Config.HANDLER_MSG_LOADING_SUCCESS:
				logInBar.setVisibility(View.INVISIBLE);
				refreshTasks = (List<Task>) msg.obj;
				System.out.println("显示的functioncode是" + functioncode + " "
						+ "本操作的areaType是" + areaType);
				/*tasks = user.getFunctionTasksFromUser(realfunctioncode,
						areaType);*/
				 if (refreshTasks.size() == 0) {
					 if (refresh) {
						 tasks.clear();
					 }
					 mainview.hideFoot1();
				 	} else {
				 		if (refresh) {
				 			tasks.clear();
				 			tasks.addAll((List<Task>) msg.obj);
				 			mainview.showFoot();
				 		} else {
				 			tasks.addAll((List<Task>) msg.obj);
				 			mainview.showFoot();
				 		}
				 }

				if (null == refreshTasks || refreshTasks.size() == 0) {
					mainview.hideFoot1();
				} else {
					mainview.showFoot();
				}
				System.out.println("下面将显示获取到的列表->");
				taskListAdapter = new TodoTaskListAdapter(
						ToDoTaskListActivity.this, tasks);
				mainview.setAdapter(taskListAdapter);
				System.out.println("上面显示了获取到的列表->");
				if(page != 1){
					mainview.setSelection(mainview.getCount() - 1); 
				}
				
				taskListAdapter.notifyDataSetChanged();
				onLoad();
				canClick = true;
				break;
			case Config.HANDLER_MSG_SEARCH_SUCCESS:
				logInBar.setVisibility(View.INVISIBLE);
				refreshTasks = (List<Task>) msg.obj;
				 if (refreshTasks.size() == 0) {
					 if (refresh) {
						 tasks.clear();
					 }
					 mainview.hideFoot1();
				 	} else {
				 		if (refresh) {
				 			tasks.clear();
				 			tasks.addAll((List<Task>) msg.obj);
				 			mainview.showFoot();
				 		} else {
				 			tasks.addAll((List<Task>) msg.obj);
				 			mainview.showFoot();
				 		}
				 	}

				if (refreshTasks.size() == 0) {
					mainview.hideFoot1();
				} else {
					mainview.showFoot();
				}
				taskListAdapter = new TodoTaskListAdapter(
						ToDoTaskListActivity.this, tasks);
				mainview.setAdapter(taskListAdapter);
				taskListAdapter.notifyDataSetChanged();
				if(page != 1){
					mainview.setSelection(mainview.getCount() - 1); 
				}
				onLoad();
				canClick = true;
				Toast.makeText(ToDoTaskListActivity.this, "查询成功",
						Toast.LENGTH_SHORT).show();
				break;
			default:
				break;
			}
			super.handleMessage(msg);
		}
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_to_do_task_list);
		initData();
		initViews();
		initEvents();
	}
	
	private void initData() {
		// 设置刷新
		MyPreference.getInstance(ToDoTaskListActivity.this).setRefreshState(
				true);
		intent = getIntent();
		bundle = intent.getExtras();
		functioncode = bundle.getString(Config.FUNCTIONCODE);
		functiontitlename = bundle.getString(Config.FUNCTIONTITLENAME);
		user = SingleSample.getInstance(this).getUser();

		functionList = user.getFunctions();
		for (Function function : functionList) {
			functionCodeList.add(function.getFunctionCode());
		}
		peopleType = Tool.getPeopleType(functionCodeList);
		InitFunctionUtil functionUtil = new InitFunctionUtil(this);
		initProgressFunctions = functionUtil.getProgressFunction();
		Log.e("initProgressFunctions", initProgressFunctions+"");

	}

	@SuppressWarnings("unchecked")
	@SuppressLint("NewApi")
	@Override
	protected void initViews() {
		// TODO Auto-generated method stub
		
		title_centeterly = (LinearLayout) findViewById(R.id.title_list_choose_centerly);
		title_list_choose_centerly = (LinearLayout) findViewById(R.id.title_list_choose_list);
		titletext = (TextView) findViewById(R.id.titlebar_list_choose_center_title);
		title_list_choose_oneTv = (TextView) findViewById(R.id.title_list_choose_one);
		title_list_choose_twoTv = (TextView) findViewById(R.id.title_list_choose_two);
		
		classify_ll = (LinearLayout) findViewById(R.id.classify_ll);
		titletext.setText(functiontitlename);
		titleListView = (ListView) findViewById(R.id.titleListView);
		Config.TITLE_ARRAY[0] = functiontitlename;

		titleListView.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> arg0, View arg1,
					int position, long arg3) {
				// 切换标题
				if (position == 0) {
					Config.TITLE_ARRAY[position] = functiontitlename;
					// titletext.setText(Config.TITLE_ARRAY[position]);
				}
				titletext.setText(Config.TITLE_ARRAY[position]);
				areaType = Config.AREACODE_ARRAY[position];
				onRefresh();

				if (classify_ll.isShown()) {
					
					classify_ll.setVisibility(View.GONE);
				}
			

			}

		});
		classify_ll.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				classify_ll.setAnimation(AnimationUtils.loadAnimation(
						ToDoTaskListActivity.this, R.anim.push_top_out2));

				classify_ll.setVisibility(View.GONE);
			}
		});

	
		/*// 标题栏选择公区派单、户内派单
		title_list_choose_onely.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				title_list_choose_oneTv.setBackground(getResources()
						.getDrawable(R.drawable.button_red_left));
				title_list_choose_oneTv.setTextColor(getResources().getColor(
						R.color.nw_tx_white));
				title_list_choose_twoTv.setBackground(getResources()
						.getDrawable(R.drawable.button_red_press_right));
				title_list_choose_twoTv.setTextColor(getResources().getColor(
						R.color.nw_tx_red));
				areaType = Config.AREACODE_INDOOR;
				System.out.println("areaType----first---11" + areaType);
				onRefresh();
			}
		});
		title_list_choose_twoly.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				title_list_choose_oneTv.setBackground(getResources()
						.getDrawable(R.drawable.button_red_press_left));
				title_list_choose_oneTv.setTextColor(getResources().getColor(
						R.color.nw_tx_red));
				title_list_choose_twoTv.setBackground(getResources()
						.getDrawable(R.drawable.button_red_right));
				title_list_choose_twoTv.setTextColor(getResources().getColor(
						R.color.nw_tx_white));
				areaType = Config.AREACODE_OUTDOOR;
				System.out.println("areaType----second--22" + areaType);
				onRefresh();
			}
		});*/

		title_centeterly.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				if (classify_ll.isShown()) {

					classify_ll.setAnimation(AnimationUtils.loadAnimation(
							ToDoTaskListActivity.this, R.anim.push_top_out2));

					classify_ll.setVisibility(View.GONE);

				} else {
					List<Map<String, Object>> titlebarlists = new ArrayList<Map<String, Object>>();
					for (int i = 0; i < Config.TITLE_ARRAY.length; i++) {
						Map<String, Object> titlebarlist = new HashMap<String, Object>();
						titlebarlist.put("title", Config.TITLE_ARRAY[i]);
						titlebarlists.add(titlebarlist);
					}
					classify_ll.setAnimation(AnimationUtils.loadAnimation(
							ToDoTaskListActivity.this, R.anim.push_top_in2));

					classify_ll.setVisibility(View.VISIBLE);
					titleAdapter = new TitleListAdapter(
							ToDoTaskListActivity.this, titlebarlists,
							R.layout.nw_task_title_list_item,
							new String[] { "title" },
							new int[] { R.id.task_title_tv });
					titleListView.setAdapter(titleAdapter);
				}
				System.out.println("areaType----first---11" + areaType);
			}
		});

		@SuppressWarnings("rawtypes")
		Map map = new HashMap<String, String>();
		Log.e("ToDoTaskList>>>functioncode", functioncode);
		if (functioncode.equals(Config.FUNCTION_REPAIRPROGRESS)) {// 维修进度
			title_centeterly.setVisibility(View.VISIBLE);
			title_list_choose_centerly.setVisibility(View.INVISIBLE);
			title_list_choose_oneTv.setText(Config.AREANAME_INDOOR);
			title_list_choose_twoTv.setText(Config.AREANAME_PUBLIC);
			map.put(MAP_TITLE, Config.FUNCTION_NAME_REPAIRPROGRESS);
			if (null != user
					.getFunctionlistFromUser(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTOFOWNER)
					&& user.getFunctionlistFromUser(
							Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTOFOWNER)
							.get(0) != null) {// 户主(如果户内维修进度列表非空)
				realfunctioncode = Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTOFOWNER;
				title_centeterly.setVisibility(View.VISIBLE);
				title_list_choose_centerly.setVisibility(View.INVISIBLE);
				titletext.setText(Config.GRID_DOING_STAGE);
				areaType = Config.AREACODE_ALL;
			} else if (null != user
					.getFunctionlistFromUser(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTOFNONOWNER)
					&& user.getFunctionlistFromUser(
							Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTOFNONOWNER)
							.get(0) != null) {// 非户主
				realfunctioncode = Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTOFNONOWNER;
				title_centeterly.setVisibility(View.VISIBLE);
				title_list_choose_centerly.setVisibility(View.INVISIBLE);
				titletext.setText(Config.GRID_DOING_STAGE);
				areaType = Config.AREACODE_ALL;
			} else if (null != user
					.getFunctionlistFromUser(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTDISPACHER)
					&& user.getFunctionlistFromUser(
							Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTDISPACHER)
							.get(0) != null) {// 派单员
				realfunctioncode = Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTDISPACHER;
				System.out.println("选择的realfunctioncode是——————"
						+ realfunctioncode);
			} else if (null != user
					.getFunctionlistFromUser(Config.FUNCTION_REAL_GETPMPROGRESSLIST)
					&& user.getFunctionlistFromUser(
							Config.FUNCTION_REAL_GETPMPROGRESSLIST).get(0) != null) {// 项目经理维修进度列表
				realfunctioncode = Config.FUNCTION_REAL_GETPMPROGRESSLIST;
				System.out.println("选择的realfunctioncode是——————"
						+ realfunctioncode);
			} else if (null != user
					.getFunctionlistFromUser(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTSEVER)
					&& user.getFunctionlistFromUser(
							Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTSEVER)
							.get(0) != null) {// 服务人员
				realfunctioncode = Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTSEVER;
			} else if (null != user
					.getFunctionlistFromUser(Config.FUNCTION_REAL_GETOUTDOORPROGRESSLISTOFOWNER)
					&& user.getFunctionlistFromUser(
							Config.FUNCTION_REAL_GETOUTDOORPROGRESSLISTOFOWNER)
							.get(0) != null) {// 户主维修进度列表（公区）
				realfunctioncode = Config.FUNCTION_REAL_GETOUTDOORPROGRESSLISTOFOWNER;
			} else if (null != user
					.getFunctionlistFromUser(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTMANAGER)
					&& user.getFunctionlistFromUser(
							Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTMANAGER)
							.get(0) != null) {// 部门派单员
				realfunctioncode = Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTMANAGER;
			} else if (null != user
					.getFunctionlistFromUser(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTSERVERMANAGER)
					&& user.getFunctionlistFromUser(
							Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTSERVERMANAGER)
							.get(0) != null) {// 部门派单员
				realfunctioncode = Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTSERVERMANAGER;
			}

		} else if (functioncode.equals(Config.FUNCTION_REPAIRDISTRIBUTE)) {// 报修分配

			title_centeterly.setVisibility(View.VISIBLE);
			title_list_choose_centerly.setVisibility(View.INVISIBLE);
			map.put(MAP_TITLE, Config.FUNCTION_NAME_REPAIRDISTRIBUTE);
			// map.put(MAP_TITLE, "11");

			realfunctioncode = Config.FUNCTION_REAL_GETDISPATCHTASKLIST;
		} else if (functioncode.equals(Config.FUNCTION_RESSIGNMENT)) {// 改派
			title_centeterly.setVisibility(View.VISIBLE);
			title_list_choose_centerly.setVisibility(View.INVISIBLE);
			titletext.setText(Config.FUNCTION_NAME_RESSIGNMENT);
			map.put(MAP_TITLE, Config.FUNCTION_NAME_RESSIGNMENT);
			realfunctioncode = Config.FUNCTION_REAL_GETREDISPATCHTASKLIST;

		} else if (functioncode.equals(Config.FUNCTION_MANAGERDISPATCH)) {// 部门主管派单

			title_centeterly.setVisibility(View.VISIBLE);
			title_list_choose_centerly.setVisibility(View.INVISIBLE);
			map.put(MAP_TITLE, Config.FUNCTION_NAME_MANAGERDISPATCH);

			realfunctioncode = Config.FUNCTION_REAL_GETMANAGERDISPATCHTASKLIST;
		} else if (functioncode.equals(Config.FUNCTION_MANAGERREDISPATCH)) {// 部门主管改派
			title_centeterly.setVisibility(View.VISIBLE);
			title_list_choose_centerly.setVisibility(View.INVISIBLE);
			titletext.setText(Config.FUNCTION_NAME_MANAGERREDISPATCH);
			map.put(MAP_TITLE, Config.FUNCTION_NAME_MANAGERREDISPATCH);
			realfunctioncode = Config.FUNCTION_REAL_GETMANAGERREDISPATCHTASKLIST;

		} else if (functioncode.equals(Config.FUNCTION_OUTTIMEREPAIR)) {// 超时派单（派单员）

			title_centeterly.setVisibility(View.VISIBLE);
			title_list_choose_centerly.setVisibility(View.INVISIBLE);
			titletext.setText(Config.FUNCTION_NAME_OUTTIMEREPAIR);
			map.put(MAP_TITLE, Config.FUNCTION_NAME_OUTTIMEREPAIR);
			realfunctioncode = Config.FUNCTION_REAL_OUTTIMEREPAIR;
		} else if (functioncode.equals(Config.FUNCTION_OUTTIMEREPAIROFDEPART)) {// 超时派单（部门派单员）

			title_centeterly.setVisibility(View.VISIBLE);
			title_list_choose_centerly.setVisibility(View.INVISIBLE);
			titletext.setText(Config.FUNCTION_NAME_OUTTIMEREPAIR);
			map.put(MAP_TITLE, Config.FUNCTION_NAME_OUTTIMEREPAIR);
			realfunctioncode = Config.FUNCTION_REAL_OUTTIMEREPAIROFDEPART;
		} else if (functioncode.equals(Config.FUNCTION_RETURNVISIT)) {// 回访
			title_centeterly.setVisibility(View.VISIBLE);
			title_list_choose_centerly.setVisibility(View.INVISIBLE);
			titletext.setText(Config.FUNCTION_NAME_RETURNVISIT);
			map.put(MAP_TITLE, Config.FUNCTION_NAME_RETURNVISIT);
			realfunctioncode = Config.FUNCTION_REAL_GETREVISITTASKLIST;
		} else if (functioncode.equals(Config.FUNCTION_REPAIRTASK)) {// 维修任务
			title_centeterly.setVisibility(View.VISIBLE);
			title_list_choose_centerly.setVisibility(View.INVISIBLE);
			titletext.setText(Config.FUNCTION_NAME_REPAIRTASK);
			map.put(MAP_TITLE, Config.FUNCTION_NAME_REPAIRTASK);
			realfunctioncode = Config.FUNCTION_REAL_GETREPAIRTASKLIST;
		} else if (functioncode.equals(Config.FUNCTION_MYAPPLY)) {// 我的提单
			areaType = Config.AREACODE_OUTDOOR;
			title_centeterly.setVisibility(View.VISIBLE);
			title_list_choose_centerly.setVisibility(View.INVISIBLE);
			titletext.setText(Config.FUNCTION_NAME_MYAPPLY);
			map.put(MAP_TITLE, Config.FUNCTION_NAME_MYAPPLY);
			realfunctioncode = Config.FUNCTION_REAL_MYAPPLY;
		} else if (functioncode.equals(Config.FUNCTION_PMREVISIT)) {// 项目经理终止回访
			title_centeterly.setVisibility(View.VISIBLE);
			title_list_choose_centerly.setVisibility(View.INVISIBLE);
			titletext.setText(Config.FUNCTION_NAME_PMREVISIT);
			map.put(MAP_TITLE, Config.FUNCTION_NAME_PMREVISIT);
			realfunctioncode = Config.FUNCTION_REAL_GETPMREVISITLIST;
		}
		Log.e("ToDoTaskList>>>realfunctioncode", realfunctioncode);
		titleList.add(map);

		LinearLayout leftlayout = (LinearLayout) findViewById(R.id.titlebar_list_choose_left_layout);
		leftlayout.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				onBackPressed();
			}
		});

		logInBar = (ProgressBar) findViewById(R.id.todo_tasklist_progressBar);

		mainview = (XListView) findViewById(R.id.lv_task_list);
		taskListAdapter = new TodoTaskListAdapter(ToDoTaskListActivity.this,
				tasks);
		mainview.setAdapter(taskListAdapter);
		mainview.setPullLoadEnable(true);
		mainview.setPullRefreshEnable(true);// 下拉刷新
		mainview.setXListViewListener(this);// 给xListView设置监听 ******
		preferences = PreferenceManager
				.getDefaultSharedPreferences(ToDoTaskListActivity.this);
		mainview.setRefreshTime(refreshUpdatedAtValue());
		// 搜索
		mClearEditText = (SearchClearEditText) findViewById(R.id.search_bar_text);
		searchbtn = (TextView) findViewById(R.id.search_bar_finish);
		mClearEditText.setFocusable(true);
		InputMethodManager imm = (InputMethodManager) mClearEditText
				.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
		imm.hideSoftInputFromWindow(mClearEditText.getWindowToken(), 0);
		// 根据输入框输入值的改变来过滤搜索
		mClearEditText.addTextChangedListener(new TextWatcher() {
			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
				// 当输入框里面的值为空，更新为原来的列表，否则为过滤数据列表
				/*
				 * editstringbuffer.append(s);
				 * editstring=editstringbuffer.toString();
				 */
			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {

			}

			@Override
			public void afterTextChanged(Editable s) {
				  editstring = s.toString();
				
				  search = editstring;
				  if(editstring.equals("")||editstring.equals("请输入关键词")){
					  search = ""; 
				  }else{ 
					  search = editstring;
				  } 
				  page = 1;
				  HashMap<String, String> orderList = new HashMap<String, String>();
				  HashMap<String, String> searchList = new HashMap<String, String>();
				  searchList.put("search", search);
				  orderList.put("statusType_typeCode", "ASC");
				  //orderList.put("statusType_typeCode", "DESC");
				  orderList.put("reporttime", "ASC");
				  //orderList.put("reporttime", "DESC"); 
				  currentPage = String.valueOf(page);
				  
					if (null != editstring) {
						if (editstring.equals("") || editstring.equals("请输入关键词")) {
							new getTasks(Page, orderList, search).start();
						} else {
							tasks.clear();
							search = editstring;
							if (functioncode.equals(Config.FUNCTION_REPAIRPROGRESS)) {// 维修进度
								if (search.contains("受") || search.contains("理")) {
									searchList.put("statusType_typeCode",
											Config.TYPECODE_DISPATCH + "-"
													+ Config.TYPECODE_REDISPATCH
													+ "-"
													+ Config.TYPECODE_SUPERVISE);
									//search = null;
									Log.d("statusType_typeCode",
											Config.TYPECODE_DISPATCH + "-"
													+ Config.TYPECODE_REDISPATCH
													+ "-"
													+ Config.TYPECODE_SUPERVISE);
								} else if (search.contains("分")
										|| search.contains("配")) {
									searchList.put("statusType_typeCode",
											Config.TYPECODE_SERVE);
									//search = null;
									Log.d("statusType_typeCode",
											Config.TYPECODE_SERVE);
								} else if (search.contains("完")
										|| search.contains("成")) {
									searchList.put("statusType_typeCode",
											Config.TYPECODE_EVALUATE);
									//search = null;
									Log.d("statusType_typeCode",
											Config.TYPECODE_EVALUATE);
								} else if (search.contains("催")
										|| search.contains("单")) {
									searchList.put("statusType_typeCode",
											Config.TYPECODE_REMINDE);
									//search = null;
									Log.d("statusType_typeCode",
											Config.TYPECODE_REMINDE);
								} else if (search.contains("待")
										|| search.contains("回")
										|| search.contains("访")) {
									searchList.put("statusType_typeCode",
											Config.TASKSTATE_REVISIT);
									//search = null;
									Log.d("statusType_typeCode",
											Config.TASKSTATE_REVISIT);
								} else if (search.contains("待")
										|| search.contains("接")
										|| search.contains("单")) {
									searchList.put("statusType_typeCode",
											Config.TASKSTATE_TORECEIVEORDER);
									//search = null;
									Log.d("statusType_typeCode",
											Config.TASKSTATE_TORECEIVEORDER);
								} else {
									 searchList.put("statusType_typeCode",
									 search);
									Log.d("statusType_typeCode", search);
								}
							} else if (functioncode
									.equals(Config.FUNCTION_REPAIRDISTRIBUTE)) {// 报修分配
								if (search.contains("待") || search.contains("分")
										|| search.contains("配")) {
									searchList.put("statusType_typeCode",
											Config.TYPECODE_DISPATCH);
									//search = null;
									Log.d("statusType_typeCode",
											Config.TYPECODE_DISPATCH);
								} else if (search.contains("督")
										|| search.contains("办")) {
									searchList.put("statusType_typeCode",
											Config.TYPECODE_SUPERVISE);
									// searchList.put("superviseTime", search);
									//search = null;
									Log.d("statusType_typeCode",
											Config.TYPECODE_SUPERVISE);
								} else {
									 searchList.put("statusType_typeCode",
									 search);
									Log.d("statusType_typeCode", search);
								}
							} else if (functioncode
									.equals(Config.FUNCTION_RESSIGNMENT)) {// 改派
								if (search.contains("已") || search.contains("分")
										|| search.contains("配")) {
									searchList.put("statusType_typeCode",
											Config.TYPECODE_SERVE);
									//search = null;
									Log.d("statusType_typeCode",
											Config.TYPECODE_SERVE);
								} else if (search.contains("申")
										|| search.contains("请")
										|| search.contains("改")
										|| search.contains("派")) {
									searchList.put("statusType_typeCode",
											Config.TYPECODE_SUPERVISE);
									//search = null;
									Log.d("statusType_typeCode",
											Config.TYPECODE_SUPERVISE);
								} else if (search.contains("催")
										|| search.contains("单")) {
									searchList.put("statusType_typeCode",
											Config.TYPECODE_REMINDE);
									//search = null;
									Log.d("statusType_typeCode",
											Config.TYPECODE_REMINDE);
								} else {
									 searchList.put("statusType_typeCode",
									 search);
									Log.d("statusType_typeCode", search);
								}
							} else if (functioncode
									.equals(Config.FUNCTION_RETURNVISIT)) {// 回访：实际搜索，1星，2星，revisit
								if (search.contains("待") || search.contains("回")
										|| search.contains("访")) {
									searchList.put("statusType_typeCode",
											Config.TYPECODE_REVISIT);
									//search = null;
									Log.d("statusType_typeCode",
											Config.TYPECODE_REVISIT);
								} else {
									 searchList.put("statusType_typeCode", search);
									Log.d("statusType_typeCode", search);
								}
							} else if (functioncode
									.equals(Config.FUNCTION_REPAIRTASK)) {// 维修任务
								if (search.contains("被") || search.contains("催")
										|| search.contains("单")) {
									searchList.put("statusType_typeCode",
											Config.TYPECODE_REMINDE);
									//search = null;
									Log.d("statusType_typeCode",
											Config.TYPECODE_REMINDE);
								} else if (search.contains("待")
										|| search.contains("维")
										|| search.contains("修")) {
									searchList.put("statusType_typeCode",
											Config.TYPECODE_SERVE);
									//search = null;
									Log.d("statusType_typeCode",
											Config.TYPECODE_SERVE);
								} else if (search.contains("待")
										|| search.contains("接")
										|| search.contains("单")) {
									searchList.put("statusType_typeCode",
											Config.TYPECODE_RECEIVEORDER);
									//search = null;
									Log.d("statusType_typeCode",
											Config.TYPECODE_RECEIVEORDER);
								} else {
									searchList.put("statusType_typeCode",search);
									Log.d("statusType_typeCode", search);
								}
							}
							;
							orderList.put("statusType_typeCode", "ASC");
							// orderList.put("statusType_typeCode", "DESC");
							orderList.put("reporttime", "ASC");
							System.out.println("orderList----->" + orderList);
							// searchList.put("search", search);
							// searchList.put("house_Id",task.getHouse_id() );
							searchList.put("projectName", search);
							searchList.put("phaseName", search);
							searchList.put("buildingName", search);
							searchList.put("unitName", search);
							searchList.put("houseName", search);
							searchList.put("reportTime", search);
							searchList.put("expectTime", search);
							searchList.put("unitName", search);
							searchList.put("superviseTime", search);
							
							searchList.put("reportTime", search);
							searchList.put("expectTime", search);
							searchList.put("acceptTime", search);
							searchList.put("dispatchTime", search);
							searchList.put("reDispatchTime", search);
							searchList.put("repairTime", search);
							searchList.put("finishTime", search);
							searchList.put("visitTime", search);
							searchList.put("evaluateTime", search);
							searchList.put("severApplyRedispatchTime", search);
							searchList.put("departDispatcherApplyRedispatchTime", search);
							System.out.println("searchList----->" + searchList);
							// searchList.put("firstTimeStr",search);
							// searchList.put("secondTimeStr", search);
							// 下面这项有多重情况!
							// searchList.put("statusType_typeCode", search);
							// orderList.put("reporttime", "DESC");
							Page = String.valueOf(page);
							new getSearchTasks(Page, orderList, searchList).start();
						}
					} else {
						new getTasks(Page, orderList, search).start();
					}
			}
		});
		
	}

	

	@Override
	protected void initEvents() {
		// TODO Auto-generated method stub
		mainview.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1,
					int position, long arg3) {
				// TODO Auto-generated method stub
				clickItemIntent(position);
			}
		});
	}

	//
	@Override
	public void onRefresh() {
		new AsyncTask<Void, Void, Void>() {

			@Override
			protected void onPreExecute() {
				if (Tool.isNetworkAvailable(ToDoTaskListActivity.this)) {
					logInBar.setVisibility(View.VISIBLE);
				} else {
					Toast.makeText(ToDoTaskListActivity.this, "请检查网络连接！",
							Toast.LENGTH_SHORT).show();
				}
				logInBar.setVisibility(View.VISIBLE);
			}

			@Override
			protected Void doInBackground(Void... params) {
				if (Tool.isNetworkAvailable(ToDoTaskListActivity.this)) {
					try {
						refresh = true;
						
						Map<String, String> map = new HashMap<String, String>();
						HashMap<String, String> orderList = new HashMap<String, String>();
						HashMap<String, String> searchList = new HashMap<String, String>();
						orderList.put("statusType_typeCode", "ASC");//DESC
						orderList.put("reporttime", "ASC");//DESC

						map.put("areaType_typecode", areaType);
						System.out.println("areaType----22" + areaType);
						// map.put("Page", "1");
						page = 1;
						Page = String.valueOf(page);
						System.out.println("page------->" + page);
						if (null != editstring) {
							if (editstring.equals("")
									|| editstring.equals("请输入关键词")) {
								new getTasks(Page, orderList, search).start();
							} else {
								search = editstring;
								if (functioncode
										.equals(Config.FUNCTION_REPAIRPROGRESS)) {// 维修进度
									if (search.contains("受")
											|| search.contains("理")) {
										searchList
												.put("statusType_typeCode",
														Config.TYPECODE_DISPATCH
																+ "-"
																+ Config.TYPECODE_REDISPATCH
																+ "-"
																+ Config.TYPECODE_SUPERVISE);
										//search = null;
									} else if (search.contains("分")
											|| search.contains("配")) {
										searchList
												.put("statusType_typeCode",
														Config.TYPECODE_SERVE
																+ "-"
																+ Config.TYPECODE_REDISPATCH
																+ "-"
																+ Config.TYPECODE_REMINDE);
										//search = null;
									} else if (search.contains("完")
											|| search.contains("成")) {
										searchList.put("statusType_typeCode",
												Config.TYPECODE_EVALUATE);
										search = null;
									} else if (search.contains("待")
											|| search.contains("接")
											|| search.contains("单")) {
										searchList.put("statusType_typeCode",
												Config.TYPECODE_RECEIVEORDER);
										//search = null;
									} else {
										 searchList.put("statusType_typeCode", search);
									}
								} else if (functioncode
										.equals(Config.FUNCTION_REPAIRDISTRIBUTE)) {// 报修分配
									if (search.contains("待")
											|| search.contains("分")
											|| search.contains("配")) {
										searchList.put("statusType_typeCode",
												Config.TYPECODE_DISPATCH);
										search = null;
									} else if (search.contains("督")
											|| search.contains("办")) {
										searchList.put("statusType_typeCode",
												Config.TYPECODE_SUPERVISE);
										// searchList.put("superviseTime",
										// search);
										//search = null;
									} else {
										 searchList.put("statusType_typeCode",search);
									}
								} else if (functioncode
										.equals(Config.FUNCTION_RESSIGNMENT)) {// 改派
									if (search.contains("已")
											|| search.contains("分")
											|| search.contains("配")) {
										searchList.put("statusType_typeCode",
												Config.TYPECODE_SERVE);
										//search = null;
									} else if (search.contains("申")
											|| search.contains("请")
											|| search.contains("改")
											|| search.contains("派")) {
										searchList.put("statusType_typeCode",
												Config.TYPECODE_SUPERVISE);
										//search = null;
									} else if (search.contains("催")
											|| search.contains("单")) {
										searchList.put("statusType_typeCode",
												Config.TYPECODE_REMINDE);
										//search = null;
									} else {
										 searchList.put("statusType_typeCode",search);
									}
								} else if (functioncode
										.equals(Config.FUNCTION_RETURNVISIT)) {// 回访
									if (search.contains("待")
											|| search.contains("回")
											|| search.contains("访")) {
										searchList.put("statusType_typeCode",
												Config.TYPECODE_REVISIT);
										//search = null;
									} else {
										 searchList.put("statusType_typeCode", search);
									}
								} else if (functioncode
										.equals(Config.FUNCTION_REPAIRTASK)) {// 维修任务
									if (search.contains("被")
											|| search.contains("催")
											|| search.contains("单")) {
										searchList.put("statusType_typeCode",
												Config.TYPECODE_REMINDE);
										//search = null;
									} else if (search.contains("待")
											|| search.contains("维")
											|| search.contains("修")) {
										searchList.put("statusType_typeCode",
												Config.TYPECODE_SERVE);
										search = null;
									} else if (search.contains("待")
											|| search.contains("接")
											|| search.contains("单")) {
										searchList.put("statusType_typeCode",
												Config.TYPECODE_RECEIVEORDER);
										//search = null;
									} else {
										 searchList.put("statusType_typeCode",
										 search);
									}
								}
								;
								orderList.put("statusType_typeCode", "ASC");
								orderList.put("reporttime", "ASC");
								searchList.put("projectName", search);
								searchList.put("phaseName", search);
								searchList.put("buildingName", search);
								searchList.put("unitName", search);
								searchList.put("houseName", search);
								searchList.put("reportTime", search);
								searchList.put("expectTime", search);
								searchList.put("unitName", search);
								searchList.put("superviseTime", search);
							
								searchList.put("reportTime", search);
								searchList.put("expectTime", search);
								searchList.put("acceptTime", search);
								searchList.put("dispatchTime", search);
								searchList.put("reDispatchTime", search);
								searchList.put("repairTime", search);
								searchList.put("finishTime", search);
								searchList.put("visitTime", search);
								searchList.put("evaluateTime", search);
								searchList.put("severApplyRedispatchTime", search);
								searchList.put("departDispatcherApplyRedispatchTime", search);
								
								Page = String.valueOf(page);
								new getSearchTasks(Page, orderList, searchList)
										.start();
							}
						} else {
							new getTasks(Page, orderList, search).start();
						}
						Log.e("onloadmore", page + "");

						preferences
								.edit()
								.putLong(UPDATED_AT + mId,
										System.currentTimeMillis()).commit();
					} catch (Exception e) {
						Log.e("GLTASKFragment", "onRefresh 网络连接问题");
						e.printStackTrace();
					}

				} else {
					
				}

				return null;
			}

			@Override
			protected void onPostExecute(Void result) {
				
			}
		}.execute(null, null, null);
	};

	@Override
	public void onResume() {
		Log.e("GLFRAGMENT", "onResume");
		super.onResume();
		
		onRefresh();

		if (taskListAdapter != null) {
			taskListAdapter.notifyDataSetChanged();
		}
	}

	private void onLoad() {
		mainview.stopRefresh();
		mainview.stopLoadMore();
		mainview.setRefreshTime(refreshUpdatedAtValue());
	}

	@Override
	public void onLoadMore() {
		mHandler.postDelayed(new Runnable() {
			@Override
			public void run() {
				refresh = false;
				HashMap<String, String> orderList = new HashMap<String, String>();
				HashMap<String, String> searchList = new HashMap<String, String>();
				orderList.put("statusType_typeCode", "ASC");
				// orderList.put("statusType_typeCode", "DESC");
				orderList.put("reporttime", "ASC");
				// orderList.put("reporttime", "DESC");
				page++;
				Page = String.valueOf(page);
				if (null != editstring) {
					if (editstring.equals("") || editstring.equals("请输入关键词")) {
						new getTasks(Page, orderList, search).start();
					} else {
						search = editstring;
						if (functioncode.equals(Config.FUNCTION_REPAIRPROGRESS)) {// 维修进度
							if (search.contains("受") || search.contains("理")) {
								searchList.put("statusType_typeCode",
										Config.TYPECODE_DISPATCH + "-"
												+ Config.TYPECODE_REDISPATCH
												+ "-"
												+ Config.TYPECODE_SUPERVISE);
								search = null;
								Log.d("statusType_typeCode",
										Config.TYPECODE_DISPATCH + "-"
												+ Config.TYPECODE_REDISPATCH
												+ "-"
												+ Config.TYPECODE_SUPERVISE);
							} else if (search.contains("分")
									|| search.contains("配")) {
								searchList.put("statusType_typeCode",
										Config.TYPECODE_SERVE);
								search = null;
								Log.d("statusType_typeCode",
										Config.TYPECODE_SERVE);
							} else if (search.contains("完")
									|| search.contains("成")) {
								searchList.put("statusType_typeCode",
										Config.TYPECODE_EVALUATE);
								search = null;
								Log.d("statusType_typeCode",
										Config.TYPECODE_EVALUATE);
							} else if (search.contains("催")
									|| search.contains("单")) {
								searchList.put("statusType_typeCode",
										Config.TYPECODE_REMINDE);
								search = null;
								Log.d("statusType_typeCode",
										Config.TYPECODE_REMINDE);
							} else if (search.contains("待")
									|| search.contains("回")
									|| search.contains("访")) {
								searchList.put("statusType_typeCode",
										Config.TASKSTATE_REVISIT);
								search = null;
								Log.d("statusType_typeCode",
										Config.TASKSTATE_REVISIT);
							} else if (search.contains("待")
									|| search.contains("接")
									|| search.contains("单")) {
								searchList.put("statusType_typeCode",
										Config.TASKSTATE_TORECEIVEORDER);
								search = null;
								Log.d("statusType_typeCode",
										Config.TASKSTATE_TORECEIVEORDER);
							} else {
								 searchList.put("statusType_typeCode",
								 search);
								Log.d("statusType_typeCode", search);
							}
						} else if (functioncode
								.equals(Config.FUNCTION_REPAIRDISTRIBUTE)) {// 报修分配
							if (search.contains("待") || search.contains("分")
									|| search.contains("配")) {
								searchList.put("statusType_typeCode",
										Config.TYPECODE_DISPATCH);
								search = null;
								Log.d("statusType_typeCode",
										Config.TYPECODE_DISPATCH);
							} else if (search.contains("督")
									|| search.contains("办")) {
								searchList.put("statusType_typeCode",
										Config.TYPECODE_SUPERVISE);
								// searchList.put("superviseTime", search);
								search = null;
								Log.d("statusType_typeCode",
										Config.TYPECODE_SUPERVISE);
							} else {
								 searchList.put("statusType_typeCode",
								 search);
								Log.d("statusType_typeCode", search);
							}
						} else if (functioncode
								.equals(Config.FUNCTION_RESSIGNMENT)) {// 改派
							if (search.contains("已") || search.contains("分")
									|| search.contains("配")) {
								searchList.put("statusType_typeCode",
										Config.TYPECODE_SERVE);
								search = null;
								Log.d("statusType_typeCode",
										Config.TYPECODE_SERVE);
							} else if (search.contains("申")
									|| search.contains("请")
									|| search.contains("改")
									|| search.contains("派")) {
								searchList.put("statusType_typeCode",
										Config.TYPECODE_SUPERVISE);
								search = null;
								Log.d("statusType_typeCode",
										Config.TYPECODE_SUPERVISE);
							} else if (search.contains("催")
									|| search.contains("单")) {
								searchList.put("statusType_typeCode",
										Config.TYPECODE_REMINDE);
								search = null;
								Log.d("statusType_typeCode",
										Config.TYPECODE_REMINDE);
							} else {
								 searchList.put("statusType_typeCode",
								 search);
								Log.d("statusType_typeCode", search);
							}
						} else if (functioncode
								.equals(Config.FUNCTION_RETURNVISIT)) {// 回访：实际搜索，1星，2星，revisit
							if (search.contains("待") || search.contains("回")
									|| search.contains("访")) {
								searchList.put("statusType_typeCode",
										Config.TYPECODE_REVISIT);
								search = null;
								Log.d("statusType_typeCode",
										Config.TYPECODE_REVISIT);
							} else {
								 searchList.put("statusType_typeCode", search);
								Log.d("statusType_typeCode", search);
							}
						} else if (functioncode
								.equals(Config.FUNCTION_REPAIRTASK)) {// 维修任务
							if (search.contains("被") || search.contains("催")
									|| search.contains("单")) {
								searchList.put("statusType_typeCode",
										Config.TYPECODE_REMINDE);
								search = null;
								Log.d("statusType_typeCode",
										Config.TYPECODE_REMINDE);
							} else if (search.contains("待")
									|| search.contains("维")
									|| search.contains("修")) {
								searchList.put("statusType_typeCode",
										Config.TYPECODE_SERVE);
								search = null;
								Log.d("statusType_typeCode",
										Config.TYPECODE_SERVE);
							} else if (search.contains("待")
									|| search.contains("接")
									|| search.contains("单")) {
								searchList.put("statusType_typeCode",
										Config.TYPECODE_RECEIVEORDER);
								search = null;
								Log.d("statusType_typeCode",
										Config.TYPECODE_RECEIVEORDER);
							} else {
								searchList.put("statusType_typeCode",search);
								Log.d("statusType_typeCode", search);
							}
						}
						;
						orderList.put("statusType_typeCode", "ASC");
						// orderList.put("statusType_typeCode", "DESC");
						orderList.put("reporttime", "ASC");
						System.out.println("orderList----->" + orderList);
						// searchList.put("search", search);
						// searchList.put("house_Id",task.getHouse_id() );
						searchList.put("projectName", search);
						searchList.put("phaseName", search);
						searchList.put("buildingName", search);
						searchList.put("unitName", search);
						searchList.put("houseName", search);
						searchList.put("reportTime", search);
						searchList.put("expectTime", search);
						searchList.put("unitName", search);
						searchList.put("superviseTime", search);
						
						searchList.put("reportTime", search);
						searchList.put("expectTime", search);
						searchList.put("acceptTime", search);
						searchList.put("dispatchTime", search);
						searchList.put("reDispatchTime", search);
						searchList.put("repairTime", search);
						searchList.put("finishTime", search);
						searchList.put("visitTime", search);
						searchList.put("evaluateTime", search);
						searchList.put("severApplyRedispatchTime", search);
						searchList.put("departDispatcherApplyRedispatchTime", search);
						System.out.println("searchList----->" + searchList);
						// searchList.put("firstTimeStr",search);
						// searchList.put("secondTimeStr", search);
						// 下面这项有多重情况!
						// searchList.put("statusType_typeCode", search);
						// orderList.put("reporttime", "DESC");
						Page = String.valueOf(page);
						new getSearchTasks(Page, orderList, searchList).start();
					}
				} else {
					new getTasks(Page, orderList, search).start();
				}
				// new getTasks(currentPage,orderList,search).start();
				Log.e("onloadmore", page + "");
				// onLoad();
			}
		}, 1000);
	}

	class getTasks extends Thread {
		public HashMap<String, String> orderList;
		public String curPage;
		public String search = "";

		public getTasks(String curPage, HashMap<String, String> orderList,
				String search) {
			super();
			this.orderList = orderList;
			this.curPage = curPage;
			this.search = search;
		}

		@Override
		public void run() {

			if (Tool.isNetworkAvailable(ToDoTaskListActivity.this)) {
				try {
					String result = null;
					String url = Config.SERVER_URL
							+ user.getFunctionlistFromUser(realfunctioncode)
									.get(0).getFunctionUrl();
					
					System.out.println("请求的realfunctioncode是——————"
							+ realfunctioncode);
					List<Task> gettasks = new ArrayList<Task>();
					Map<String, String> map = new HashMap<String, String>();
					map.put("page", curPage);
					map.put("functionCode", realfunctioncode);
					map.put("areaType_typecode", areaType);
					Log.e("areaType_typecode", areaType);
				
					Log.e("我访问的url是：", url);
					Log.e("我访问functionCode的是：", realfunctioncode);
					String setsessionid = "";
					user = SingleSample.getInstance(ToDoTaskListActivity.this)
							.getUser();
					if (null != user) {
						if (null != user.getSessionId()
								&& !user.getSessionId().equals("")) {
							setsessionid = user.getSessionId();
						}
					}
					result = HttpUtil.postRequestSe(url, map, setsessionid);
					result = result.replace("rows", "tasks");
					Log.e("页数", curPage);
					Log.e("分页加载的result", result);
					/*String message = new JSONObject(result)
							.getString("message");*/
					//String flag = new JSONObject(result).getString("flag");
					String rows = new JSONObject(result).getString("tasks");
					result = null;
					java.lang.reflect.Type type = new TypeToken<List<Task>>() {
					}.getType();
					Gson gson = new Gson();
					gettasks = gson.fromJson(rows, type);
					List<Task> changetasks = new ArrayList<Task>();
					// 先新建一个tts列表，无论这个任务是否存在，都加入进去，减少出错。
					if (null != gettasks) {

						for (Task task : gettasks) {
							System.out.println("areaType是" + areaType);
						
							task = Tool.setTaskAll(realfunctioncode, peopleType,
									task, user);
							changetasks.add(task);
						}
					} else {
						mHandler.obtainMessage(Config.HANDLE_MSG_RFESH_FAIL, "获取任务出错")
								.sendToTarget();
					}
					mHandler.obtainMessage(Config.HANDLER_MSG_LOADING_SUCCESS,
							changetasks).sendToTarget();

				} catch (Exception e) {
					mHandler.obtainMessage(Config.HANDLE_MSG_RFESH_FAIL, "json解析出错")
							.sendToTarget();
					Log.e("GLTASKFragment", "onRefresh 网络连接问题");
					
					e.printStackTrace();
				}
			} else {
				mHandler.obtainMessage(Config.HANDLE_MSG_RFESH_FAIL, "请检查网络连接！")
						.sendToTarget();
				// handler.sendEmptyMessage(1);
			}

		}

	}

	class getSearchTasks extends Thread {
		public HashMap<String, String> orderList;
		public HashMap<String, String> searchList;
		public String curPage;
		//public String search = "";

		public getSearchTasks(String curPage,
				HashMap<String, String> orderList,
				HashMap<String, String> searchList) {
			super();
			this.orderList = orderList;
			this.curPage = curPage;
			this.searchList = searchList;
		}

		@Override
		public void run() {

			if (Tool.isNetworkAvailable(ToDoTaskListActivity.this)) {
				try {
					String url = Config.SERVER_URL
							+ user.getFunctionlistFromUser(realfunctioncode)
									.get(0).getFunctionUrl();
					List<Task> gettasks = new ArrayList<Task>();
					Map<String, String> map = new HashMap<String, String>();
					map.put("page", curPage);
					map.put("search", search);
					/*map.put("searchList", new Gson().toJson(searchList));
					map.put("orderList", new Gson().toJson(orderList));*/

					map.put("areaType_typecode", areaType);
					System.out.println("areaType----44" + areaType);

					map.put("functionCode", realfunctioncode);
					map.put("repairId", "");
					// map.put("statusType_typeCode",task1.getStatusType_typeCode());
					String result = null;
					String setsessionid = "";
					user = SingleSample.getInstance(ToDoTaskListActivity.this)
							.getUser();
					if (null != user) {
						if (null != user.getSessionId()
								&& !user.getSessionId().equals("")) {
							setsessionid = user.getSessionId();
						}
					}
					result = HttpUtil.postRequestSe(url, map, setsessionid);
					result = result.replace("rows", "tasks");
					Log.e("我访问的url是：", url);
					Log.e("我访问functionCode的是：", realfunctioncode);
					Log.e("我搜索的是：", editstring);
					Log.e("页数", curPage);
					Log.e("搜索的result", result);
					/*String message = new JSONObject(result)
							.getString("message");*/
					String flag = new JSONObject(result).getString("flag");
					String rows = new JSONObject(result).getString("tasks");
					String total = new JSONObject(result).getString("total");
					result = null;
					java.lang.reflect.Type type = new TypeToken<List<Task>>() {
					}.getType();
					Gson gson = new Gson();
					gettasks = gson.fromJson(rows, type);
					
					if (flag.equals(Config.CONNECT_SUCCESS2)) {
						List<Task> nontasks = new ArrayList<Task>();
						user.setTasks(nontasks);
						user.update(user.getId());
						ArrayList<Task> searchtts = new ArrayList<Task>();

						if (null != gettasks) {

							for (Task task : gettasks) {
								
								task = Tool.setTaskAll(realfunctioncode,
										peopleType, task, user);
								searchtts.add(task);
							}
						} else {
							mHandler.obtainMessage(Config.HANDLE_MSG_SEARCH_FAIL,
									"获取任务出错").sendToTarget();
						}
						mHandler.obtainMessage(
								Config.HANDLER_MSG_SEARCH_SUCCESS, searchtts)
								.sendToTarget();
					} else {
						mHandler.obtainMessage(Config.HANDLE_MSG_SEARCH_FAIL, "搜索失败")
								.sendToTarget();
					}

				} catch (Exception e) {
					mHandler.obtainMessage(Config.HANDLE_MSG_RFESH_FAIL, "json解析出错")
							.sendToTarget();
					Log.e("GLTASKFragment", "onRefresh 网络连接问题");
					/*
					 * Toast.makeText(getActivity(), "网络连接出错" ,
					 * Toast.LENGTH_SHORT).show();
					 */
					e.printStackTrace();
				}
			} else {
				mHandler.obtainMessage(Config.HANDLE_MSG_RFESH_FAIL, "请检查网络连接！")
						.sendToTarget();
				// handler.sendEmptyMessage(1);
			}

		}
	}

	private void clickItemIntent(int position) {
		if (canClick && Tool.isNetworkAvailable(ToDoTaskListActivity.this)) {
			//boolean isReporter = false;
			Intent i = new Intent();
			Bundle b = new Bundle();
			position = position - 1;
			
			Task intenttask = tasks.get(position);
			boolean isReporter = Tool.isReporter(intenttask, user.getUserId(), peopleType);
			functionPeopleType = Tool.getFunctionPeopleType(functioncode, peopleType, isReporter);
			InitTaskState initTS = Tool.getInitTaskState(user, intenttask, initProgressFunctions, functioncode, functionPeopleType);
			InitProgressFunction initPF = Tool.getInitProgressFunction(user, intenttask, initProgressFunctions, functioncode, functionPeopleType);
			if(StringUtil.isStringEqual(initTS.getSegue(), "1")){//单节点详情界面
				i = new Intent(ToDoTaskListActivity.this,
						SingleDetailActivity.class);
			}else if(StringUtil.isStringEqual(initTS.getSegue(), "2")){//双节点详情界面
				i = new Intent(ToDoTaskListActivity.this,
						DoubleDetailActivity.class);
			}
			b.putSerializable(Config.INITTASTSTATE, initTS);
			b.putSerializable(Config.INITPROGRESSFUNCTION, initPF);
			b.putSerializable(Config.TASK, intenttask);
			b.putBoolean(Config.ISREPORTER, isReporter);
			b.putString(Config.PEOPLETYPE, peopleType);
			b.putString(Config.FUNCTIONCODE, realfunctioncode);
			System.out.println("列表中维修位置"+tasks.get(position).getHouseAllName());
			b.putString(Config.HOUSEFULLNAME, tasks.get(position).getHouseAllName());
			b.putString(Config.HOUSEID, tasks.get(position).getHouse_id());
			i.putExtras(b);
			startActivity(i);
			/*tasks.get(position).setIschange(2);
			tasks.get(position).setUser(user);
			String taskcode = tasks.get(position).getStatusType_typeCode();
			isReporter = Tool.isReporter(tasks.get(position), user.getUserId(), peopleType);
			Log.e("列表点击>>" + Config.FUNCTIONCODE, realfunctioncode);
			Log.e("列表点击>>" + Config.PEOPLETYPE, peopleType);
			Log.e("列表点击>>" + Config.STATUS_TYPE_CODE, tasks.get(position)
					.getStatusType_typeCode());
			// 业主
			if (realfunctioncode
					.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTOFOWNER)// 户主维修进度（户内）
					|| realfunctioncode
							.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTOFNONOWNER)// 非户主维修进度（户内）
					|| realfunctioncode
							.equals(Config.FUNCTION_REAL_GETOUTDOORPROGRESSLISTOFOWNER)// 户主维修进度（公区）
			
					) {
				if (taskcode.equals(Config.TYPECODE_DISPATCH)// dispatch
						|| taskcode.equals(Config.TYPECODE_REDISPATCH)// redispatch
						|| taskcode.equals(Config.TYPECODE_SUPERVISE)// //
																		// surpervise
						|| taskcode.equals(Config.TYPECODE_MANAGERDISPATCH)// managerSupervise
						|| taskcode.equals(Config.TYPECODE_MANAGERREDISPATCH)// managerRedispatch
						|| taskcode.equals(Config.TYPECODE_MANAGERSUPERVISE)// managerSupervise
						|| taskcode.equals(Config.TYPECODE_MANAGERAROMD)// managerApplyRedispatchOnManagerDispatch
						|| taskcode.equals(Config.TYPECODE_MANAGERPROG)// managerApplyRedispatchOnGet
						|| taskcode.equals(Config.TYPECODE_MANAGERAROS)// managerApplyRedispatchOnServe
						|| taskcode.equals(Config.TYPECODE_SERVERAROG)// serverApplyRedispatchOnGet
						|| taskcode.equals(Config.TYPECODE_SERVERAROS)// serverApplyRedispatchOnServe
						|| taskcode.equals(Config.TYPECODE_RECEIVEORDER)// receivorder
						|| taskcode.equals(Config.TYPECODE_SERVE)// serve
						|| taskcode.equals(Config.TYPECODE_REMINDE)// remind
				) {
					i = new Intent(ToDoTaskListActivity.this,
							ServiceScheduleActivity.class);
				} else if (taskcode.equals(Config.TYPECODE_EVALUATE)// evaluate
						|| taskcode.equals(Config.TYPECODE_REVISIT)// revisit
						|| taskcode.equals(Config.TYPECODE_FINISH)// finish
				) {

					i = new Intent(ToDoTaskListActivity.this,
							ServiceScheduleAccomplishActivity.class);

				}
			}// 派单员
			else if (realfunctioncode
					.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTDISPACHER)// 派单员维修进度
					|| realfunctioncode
							.equals(Config.FUNCTION_REAL_GETDISPATCHTASKLIST)// 派单员-报修分配
					|| realfunctioncode
							.equals(Config.FUNCTION_REAL_GETREDISPATCHTASKLIST)// 派单员-改派
					|| realfunctioncode
							.equals(Config.FUNCTION_REAL_OUTTIMEREPAIR)// 派单员-超时改派
					|| realfunctioncode
							.equals(Config.FUNCTION_REAL_GETREVISITTASKLIST)// 派单员-回访
					||realfunctioncode.equals(Config.FUNCTION_REAL_MYAPPLY) && peopleType.equals(Config.DISPATCHER)//我的提单（派单员）
					) {
				if (taskcode.equals(Config.TYPECODE_DISPATCH)// dispatch 分配
						|| taskcode.equals(Config.TYPECODE_SUPERVISE)// supervise
																		// 督办
						|| taskcode.equals(Config.TYPECODE_REDISPATCH)// redispatch
						|| taskcode.equals(Config.TYPECODE_MANAGERDISPATCH)// managerDispatch
																			// 部门主管分配
						|| taskcode.equals(Config.TYPECODE_MANAGERSUPERVISE)// managerSupervise
																			// 部门主管督办
						|| taskcode.equals(Config.TYPECODE_MANAGERREDISPATCH)// managerSupervise
																				// 部门主管督办
						|| taskcode.equals(Config.TYPECODE_MANAGERAROMD)// managerApplyRedispatchOnManagerDispatch
						|| taskcode.equals(Config.TYPECODE_MANAGERPROG)// managerApplyRedispatchOnGet
						|| taskcode.equals(Config.TYPECODE_MANAGERAROS)// managerApplyRedispatchOnServe
						||taskcode.equals(Config.TYPECODE_SERVERAROG)// serverApplyRedispatchOnGet
						|| taskcode.equals(Config.TYPECODE_SERVERAROS)// serverApplyRedispatchOnServe
						|| taskcode.equals(Config.TYPECODE_RECEIVEORDER)// receivorder
						|| taskcode.equals(Config.TYPECODE_SERVE)// serve
						|| taskcode.equals(Config.TYPECODE_REMINDE)//remind
				) {
					i = new Intent(ToDoTaskListActivity.this,
							AssignAndReassignTaskActivity.class);
				}else if (taskcode.equals(Config.TYPECODE_EVALUATE)// evaluate
						|| taskcode.equals(Config.TYPECODE_REVISIT)// revisit
						|| taskcode.equals(Config.TYPECODE_FINISH)// finish
				) {
					i = new Intent(ToDoTaskListActivity.this,
							ServiceScheduleAccomplishActivity.class);
				}

			} // 项目经理
			else if (realfunctioncode
					.equals(Config.FUNCTION_REAL_GETPMPROGRESSLIST)// 项目经理-维修进度
					|| realfunctioncode
							.equals(Config.FUNCTION_REAL_GETPMREVISITLIST)// 项目经理-终止回访
					||realfunctioncode.equals(Config.FUNCTION_REAL_MYAPPLY) && peopleType.equals(Config.DEPART_MANAGER)//我的提单（项目经理）
					) {
				if (taskcode.equals(Config.TYPECODE_DISPATCH)// dispatch
						||taskcode.equals(Config.TYPECODE_SUPERVISE)// supervise
						||taskcode.equals(Config.TYPECODE_REDISPATCH)// redispatch
						|| taskcode.equals(Config.TYPECODE_MANAGERAROMD)// managerApplyRedispatchOnManagerDispatch
						|| taskcode.equals(Config.TYPECODE_MANAGERPROG)// managerApplyRedispatchOnGet
						|| taskcode.equals(Config.TYPECODE_MANAGERAROS)// managerApplyRedispatchOnServe
						|| taskcode.equals(Config.TYPECODE_MANAGERDISPATCH)// managerDispatch部门主管分配
						|| taskcode.equals(Config.TYPECODE_MANAGERSUPERVISE)// managerDispatch部门主管分配
						||taskcode.equals(Config.TYPECODE_SERVERAROG)// serverApplyRedispatchOnGet
						|| taskcode.equals(Config.TYPECODE_SERVERAROS)// serverApplyRedispatchOnServe
						||taskcode.equals(Config.TYPECODE_MANAGERREDISPATCH)// managerSupervise部门主管督办
						|| taskcode.equals(Config.TYPECODE_RECEIVEORDER)// receivorder
						|| taskcode.equals(Config.TYPECODE_SERVE)// serve
						|| taskcode.equals(Config.TYPECODE_REMINDE)// remind
				) {

					i = new Intent(ToDoTaskListActivity.this,
							ServiceScheduleActivity.class);
				} else if (taskcode.equals(Config.TYPECODE_EVALUATE)// evaluate
						|| taskcode.equals(Config.TYPECODE_REVISIT)// revisit
						|| taskcode.equals(Config.TYPECODE_FINISH)// finish
				) {

					i = new Intent(ToDoTaskListActivity.this,
							ServiceScheduleAccomplishActivity.class);
				}
			}// 部门派单员
			else if (realfunctioncode
					.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTMANAGER)// 部门主管-维修进度
					|| realfunctioncode
							.equals(Config.FUNCTION_REAL_GETMANAGERDISPATCHTASKLIST)// 部门主管-派单
					|| realfunctioncode
							.equals(Config.FUNCTION_REAL_OUTTIMEREPAIROFDEPART)// 部门主管-超时改派
					|| realfunctioncode
							.equals(Config.FUNCTION_REAL_GETMANAGERREDISPATCHTASKLIST)// 部门主管-改派
					|| realfunctioncode.equals(Config.FUNCTION_REAL_MYAPPLY) && peopleType.equals(Config.DEPART_DISPATCHER)&& isReporter//我的提单（部门派单员）
					) {
				if (taskcode.equals(Config.TYPECODE_MANAGERDISPATCH)// managerDispatch部门主管分配
						|| taskcode.equals(Config.TYPECODE_MANAGERSUPERVISE)// managerSupervise部门主管督办
						|| taskcode.equals(Config.TYPECODE_MANAGERREDISPATCH)// managerRedispatch部门主管改派
						|| taskcode.equals(Config.TYPECODE_RECEIVEORDER)// receivorder
						|| taskcode.equals(Config.TYPECODE_SERVE)// serve
						|| taskcode.equals(Config.TYPECODE_SERVERAROS)// serverApplyRedispatchOnServe
						|| taskcode.equals(Config.TYPECODE_SERVERAROG)// serverApplyRedispatchOnGet
						|| taskcode.equals(Config.TYPECODE_REMINDE)// remind
						|| taskcode.equals(Config.TYPECODE_DISPATCH)// dispatch
				) {
					i = new Intent(ToDoTaskListActivity.this,
							AssignAndReassignTaskActivity.class);
				} else if (taskcode.equals(Config.TYPECODE_EVALUATE)// evaluate
						|| taskcode.equals(Config.TYPECODE_REVISIT)// revisit
						|| taskcode.equals(Config.TYPECODE_FINISH)// finish
				) {

					i = new Intent(ToDoTaskListActivity.this,
							ServiceScheduleAccomplishActivity.class);
				} else if (taskcode.equals(Config.TYPECODE_MANAGERAROMD)// evaluate
						
				) {

					i = new Intent(ToDoTaskListActivity.this,
							ServiceScheduleActivity.class);
				}
			}
			// 部门经理
			else if (realfunctioncode
					.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTSERVERMANAGER)// 部门经理-维修进度
			||realfunctioncode.equals(Config.FUNCTION_REAL_MYAPPLY) && peopleType.equals(Config.SERVER_MANAGER)//我的提单（部门经理）
					) {
				if (taskcode.equals(Config.TYPECODE_DISPATCH)// managerDispatch部门主管分配
						|| taskcode.equals(Config.TYPECODE_SUPERVISE)// managerSupervise部门主管督办
						|| taskcode.equals(Config.TYPECODE_MANAGERDISPATCH)// managerDispatch部门主管分配
						|| taskcode.equals(Config.TYPECODE_MANAGERSUPERVISE)// managerSupervise部门主管督办
						|| taskcode.equals(Config.TYPECODE_MANAGERREDISPATCH)// managerRedispatch部门主管改派
						|| taskcode.equals(Config.TYPECODE_MANAGERAROMD)// managerDispatch部门主管分配
						|| taskcode.equals(Config.TYPECODE_MANAGERPROG)// managerSupervise部门主管督办
						|| taskcode.equals(Config.TYPECODE_MANAGERAROS)// managerRedispatch部门主管改派
						|| taskcode.equals(Config.TYPECODE_RECEIVEORDER)// receivorder
						|| taskcode.equals(Config.TYPECODE_SERVE)// serve
						|| taskcode.equals(Config.TYPECODE_SERVERAROS)// serverApplyRedispatchOnServe
						|| taskcode.equals(Config.TYPECODE_SERVERAROG)// serverApplyRedispatchOnGet
						|| taskcode.equals(Config.TYPECODE_REMINDE)// remind
				) {
					i = new Intent(ToDoTaskListActivity.this,
							ServiceScheduleActivity.class);
				} else if (taskcode.equals(Config.TYPECODE_EVALUATE)// evaluate
						|| taskcode.equals(Config.TYPECODE_REVISIT)// revisit
						|| taskcode.equals(Config.TYPECODE_FINISH)// finish
				) {

					i = new Intent(ToDoTaskListActivity.this,
							ServiceScheduleAccomplishActivity.class);
				}
			}
			// 维修人员
			else if (realfunctioncode
					.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTSEVER)// 维修人员维修进度
					|| realfunctioncode
							.equals(Config.FUNCTION_REAL_GETREPAIRTASKLIST)// 维修人员-维修任务
					||realfunctioncode.equals(Config.FUNCTION_REAL_MYAPPLY) && peopleType.equals(Config.SERVER) && isReporter//我的提单（维修人员）
			) {
					//isServerReport = true;
					if (taskcode.equals(Config.TYPECODE_EVALUATE)// evaluate
							|| taskcode.equals(Config.TYPECODE_REVISIT)// revisit
							|| taskcode.equals(Config.TYPECODE_FINISH)// finish
					) {
						i = new Intent(ToDoTaskListActivity.this,
								ServiceScheduleAccomplishActivity.class);
					}else{
						
						i = new Intent(ToDoTaskListActivity.this,
								ServiceScheduleActivity.class);
					}
					
					
					
			}else if (realfunctioncode.equals(Config.FUNCTION_REAL_MYAPPLY)&& !isReporter//我的提单（操作者不是提单人）
			) {
				if (taskcode.equals(Config.TYPECODE_DISPATCH)// dispatch
						|| taskcode.equals(Config.TYPECODE_REDISPATCH)// redispatch
						|| taskcode.equals(Config.TYPECODE_SUPERVISE)// //
																		// surpervise
						|| taskcode.equals(Config.TYPECODE_MANAGERDISPATCH)// managerSupervise
						|| taskcode.equals(Config.TYPECODE_MANAGERREDISPATCH)// managerRedispatch
						|| taskcode.equals(Config.TYPECODE_MANAGERSUPERVISE)// managerSupervise
						|| taskcode.equals(Config.TYPECODE_MANAGERAROMD)// managerApplyRedispatchOnManagerDispatch
						|| taskcode.equals(Config.TYPECODE_MANAGERPROG)// managerApplyRedispatchOnGet
						|| taskcode.equals(Config.TYPECODE_MANAGERAROS)// managerApplyRedispatchOnServe
						|| taskcode.equals(Config.TYPECODE_SERVERAROG)// serverApplyRedispatchOnGet
						|| taskcode.equals(Config.TYPECODE_SERVERAROS)// serverApplyRedispatchOnServe
						|| taskcode.equals(Config.TYPECODE_RECEIVEORDER)// receivorder
						|| taskcode.equals(Config.TYPECODE_SERVE)// serve
						|| taskcode.equals(Config.TYPECODE_REMINDE)// remind
				) {
					i = new Intent(ToDoTaskListActivity.this,
							ServiceScheduleActivity.class);
				} else if (taskcode.equals(Config.TYPECODE_EVALUATE)// evaluate
						|| taskcode.equals(Config.TYPECODE_REVISIT)// revisit
						|| taskcode.equals(Config.TYPECODE_FINISH)// finish
				) {

					i = new Intent(ToDoTaskListActivity.this,
							ServiceScheduleAccomplishActivity.class);

				}
			}
			b.putString(Config.HOUSEID, tasks.get(position).getHouse_id());
			b.putBoolean(Config.ISREPORTER, isReporter);
			b.putString(Config.PEOPLETYPE, peopleType);
			if (tasks.get(position).getAreaType_typeCode() != null) {
				b.putString(Config.AREATYPE, tasks.get(position)
						.getAreaType_typeCode());
			} else if (tasks.get(position).getHouse_houseType_typeCode() != null) {
				b.putString(Config.AREATYPE, tasks.get(position)
						.getHouse_houseType_typeCode());
			}
			b.putString(Config.HOUSEID, tasks.get(position)
					.getHouse_id());
			b.putString(Config.FUNCTIONCODE, realfunctioncode);
			b.putString(Config.TASKSTATE, tasks.get(position).getTaskState());
			b.putString(Config.STATUS_TYPE_CODE, tasks.get(position)
					.getStatusType_typeCode());
			b.putString(Config.REPAIRID, tasks.get(position).getRepairId());
			b.putString(Config.HOUSEFULLNAME, tasks.get(position).getHouseAllName());
			Log.e("列表跳转>>" + Config.TASK_ID, tasks.get(position).getId() + "");
			Log.e("列表跳转>>" + Config.TASKSTATE, tasks.get(position)
					.getTaskState());
			Log.e("列表跳转>>" + Config.STATUS_TYPE_CODE, tasks.get(position)
					.getStatusType_typeCode());
			Log.e("列表跳转>>" + Config.REPAIRID, tasks.get(position).getRepairId());
			Log.e("列表跳转>>" + Config.FUNCTIONCODE, realfunctioncode);
			i.putExtras(b);
			startActivity(i);*/
		} else {
			Toast.makeText(ToDoTaskListActivity.this, "请检查网络连接！！",
					Toast.LENGTH_SHORT).show();
		}
};
	

		/**
		 * 重写Adapter
		 * 
		 * @author Administrator
		 * 
		 */
		class TitleListAdapter extends SimpleAdapter {

			public TitleListAdapter(Context context,
					List<? extends Map<String, ?>> data, int resource,
					String[] from, int[] to) {
				super(context, data, resource, from, to);
			}

			@Override
			public int getCount() {
				// TODO Auto-generated method stub
				Log.e("TitleListAdapter", "getCount()");
				return super.getCount();
			}

			@Override
			public View getView(int position, View convertView, ViewGroup parent) {
				Log.e("TitleListAdapter", "getView()");
				View view = super.getView(position, convertView, parent);

				//TextView item = (TextView) view.findViewById(R.id.title_list_tv);
			
				return view;
			}

		}
	/**
	 * 刷新下拉头中上次更新时间的文字描述。
	 */
	private String refreshUpdatedAtValue() {
		lastUpdateTime = preferences.getLong(UPDATED_AT + mId, -1);
		long currentTime = System.currentTimeMillis();
		long timePassed = currentTime - lastUpdateTime;
		long timeIntoFormat;
		String updateAtValue;
		if (lastUpdateTime == -1) {
			updateAtValue = getResources().getString(R.string.not_updated_yet);
		} else if (timePassed < 0) {
			updateAtValue = getResources().getString(R.string.time_error);
		} else if (timePassed < ONE_MINUTE) {
			updateAtValue = getResources().getString(R.string.updated_just_now);
		} else if (timePassed < ONE_HOUR) {
			timeIntoFormat = timePassed / ONE_MINUTE;
			String value = timeIntoFormat + "分钟";
			updateAtValue = String.format(
					getResources().getString(R.string.updated_at), value);
		} else if (timePassed < ONE_DAY) {
			timeIntoFormat = timePassed / ONE_HOUR;
			String value = timeIntoFormat + "小时";
			updateAtValue = String.format(
					getResources().getString(R.string.updated_at), value);
		} else if (timePassed < ONE_MONTH) {
			timeIntoFormat = timePassed / ONE_DAY;
			String value = timeIntoFormat + "天";
			updateAtValue = String.format(
					getResources().getString(R.string.updated_at), value);
		} else if (timePassed < ONE_YEAR) {
			timeIntoFormat = timePassed / ONE_MONTH;
			String value = timeIntoFormat + "个月";
			updateAtValue = String.format(
					getResources().getString(R.string.updated_at), value);
		} else {
			timeIntoFormat = timePassed / ONE_YEAR;
			String value = timeIntoFormat + "年";
			updateAtValue = String.format(
					getResources().getString(R.string.updated_at), value);
		}

		return updateAtValue;
	}

	/**
	 * 一分钟的毫秒值，用于判断上次的更新时间
	 */
	public static final long ONE_MINUTE = 60 * 1000;

	/**
	 * 一小时的毫秒值，用于判断上次的更新时间
	 */
	public static final long ONE_HOUR = 60 * ONE_MINUTE;

	/**
	 * 一天的毫秒值，用于判断上次的更新时间
	 */
	public static final long ONE_DAY = 24 * ONE_HOUR;

	/**
	 * 一月的毫秒值，用于判断上次的更新时间
	 */
	public static final long ONE_MONTH = 30 * ONE_DAY;

	/**
	 * 一年的毫秒值，用于判断上次的更新时间
	 */
	public static final long ONE_YEAR = 12 * ONE_MONTH;

	/**
	 * 上次更新时间的字符串常量，用于作为SharedPreferences的键值
	 */
	private static final String UPDATED_AT = "updated_at";

	/**
	 * 用于存储上次更新时间
	 */
	private SharedPreferences preferences;

	/**
	 * 上次更新时间的毫秒值
	 */
	private long lastUpdateTime;
	/**
	 * 为了防止不同界面的下拉刷新在上次更新时间上互相有冲突，使用id来做区分
	 */
	private int mId = -1;

	public static boolean stopLoadMoreFlag() {
		boolean stoploadflag = false;
		return stoploadflag;

	}
}
